/**
 * sns-话题聚类
 */
;
(function($, window, document, undefined) {
    var TopicCluster = function(el, opts) {
        this.el = el;
        this.defaults = {
            theme: 'macarons'
        };
        this.options = $.extend({}, this.defaults, opts);
    }

    TopicCluster.prototype = {
        init: function() {
            var me = this,
                el = me.el;

            if (el.attr('data-initialized') == 'true') {
                return me;
            }

            el.find('.chart').each(function(i, chart) {
                var elChart = $(chart);
                me.initChart(elChart);
            });

            me.bindEvents();


            el.attr('data-initialized', 'true');
            return me;
        },


        /**
         * [bindEvents description]
         * @return {[type]} [description]
         */
        bindEvents: function() {
            var me = this,
                el = me.el;

        },

        initChart: function(elChart, option) {
            var me = this,
                el = me.el,
                option;

            comChart = echarts.init(elChart[0], me.options.theme);
            option = {
                title: {
                    text: '话题标题',
                    x: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                calculable: true,
                series: [{
                    name: '访问来源',
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '50%'],
                    data: [{
                        value: 335,
                        name: '字段一'
                    }, {
                        value: 310,
                        name: '字段二'
                    }, {
                        value: 234,
                        name: '字段三'
                    }, {
                        value: 135,
                        name: '字段四'
                    }, {
                        value: 1548,
                        name: '字段五'
                    }, {
                        value: 335,
                        name: '字段六'
                    }, {
                        value: 310,
                        name: '字段7'
                    }, {
                        value: 234,
                        name: '字段8'
                    }, {
                        value: 135,
                        name: '字段9'
                    }, {
                        value: 8,
                        name: '字段10'
                    }]
                }]
            };


            comChart.setOption(option);
        }
    }

    $.fn.TopicCluster = function(opts) {
        var me = this,
            el = me.el,
            comTopicCluster;

        // 如果没有被初始化过
        if (!(el && el.length && el.attr('data-initialized') != 'true')) {
            comTopicCluster = new TopicCluster(this, opts);
        }

        return comTopicCluster.init();
    }
})(jQuery, window, document);
